//
// Created by LiuYou on 2021/8/3.
//

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sys/msg.h>
#include "Proto.hpp"


int main() {
    int keyProj = static_cast<int>(KEY_PROJ);
    key_t key = ftok( KEY_PATH, keyProj );
    if (key < 0) {
        perror( "ftok()" );
        exit( 1 );
    }

    int msgId = msgget( key, 0 );
    if (msgId < 0) {
        perror( "msgget()" );
        exit( 1 );
    }

    Msg sendBuf;
    sendBuf.type = 1;
    strcpy( sendBuf.name, "Alan" );
    sendBuf.math = rand() % 100;
    sendBuf.chinese = rand() % 100;
    int ret = msgsnd( msgId, &sendBuf, sizeof( sendBuf ) - sizeof( long ),
                      0 );
    if (ret < 0) {
        perror( "msgsnd()" );
        exit( 1 );
    }

    puts( "OK" );

//    msgctl();

    exit( 0 );
}